package com.iweb.hello;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Send {

    // 队列的名称
    private final static String QUEUE_NAME = "hello-world";

    public static void main(String[] args) throws Exception {
        // 创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("122.112.160.198");
        factory.setUsername("guest");
        factory.setPassword("guest");

        // 获取会话
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        // 声明队列
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);

        // 需要发送的消息
        String message = "hello world";
        channel.basicPublish("", QUEUE_NAME, null, message.getBytes());

        System.out.println("发送消息:" + message);

        channel.close();
        connection.close();
    }
}
